package com.demo.apparel.mapper.web;

import com.demo.apparel.entity.ClothesType;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface ClothesTypeMapper {

    @Insert("INSERT INTO clothes_type (id, type_name, keywords, sort, create_time, category) " +
            "VALUES (#{id}, #{typeName}, #{keywords}, #{sort}, #{createTime}, #{category})")
    void insertClothesType(ClothesType clothesType);
    @Select("SELECT id, type_name, category,keywords  FROM clothes_type")
    List<Map<String, Object>> getAllClothesType();

    @Select("SELECT COUNT(1) FROM clothes_type WHERE id = #{id}")
    int countById(@Param("id") String id);

    @Select("SELECT MAX(CAST(id AS UNSIGNED)) FROM clothes_type")
    String getMaxId();

    @Update("UPDATE clothes_type SET type_name = #{typeName}, keywords = #{keywords}, category = #{category} WHERE id = #{id}")
    int updateClothesType(ClothesType clothesType);

    /**
     * 根据category标识删除对应的小类
     */
    @Delete("DELETE FROM clothes_type WHERE category = #{category}")
    void deleteByCategory(Integer category);

    @Delete("DELETE FROM clothes_type WHERE id = #{id}")
    int deleteById(@Param("id") String id);

}
